//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------


using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.BLL.Entities;
using Tathata.Common.Caching;
using Tathata.Common.DAL.Managers;
using System;
namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Category template manager
    /// </summary>
    public class CategoryTemplateManager
    {
        #region Constants
        private const string CATEGORYTEMPLATES_ALL_KEY = "Nop.categorytemplate.all";
        private const string CATEGORYTEMPLATES_BY_ID_KEY = "Nop.categorytemplate.id-{0}";
        #endregion

        #region Methods
        /// <summary>
        /// Deletes a category template
        /// </summary>
        /// <param name="CategoryTemplateID">Category template identifier</param>
        public static void DeleteCategoryTemplate(int CategoryTemplateID)
        {
            CategoryTemplateDBManager.DeleteCategoryTemplate(CategoryTemplateID);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_ALL_KEY);
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_BY_ID_KEY);
            }
        }

        /// <summary>
        /// Gets all category templates
        /// </summary>
        /// <returns>Category template collection</returns>
        public static CategoryTemplateCollection GetAllCategoryTemplates()
        {
            string key = string.Format(CATEGORYTEMPLATES_ALL_KEY);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (CategoryTemplateCollection)obj2;
            }

            CategoryTemplateCollection categoryTemplateCollection = CategoryTemplateDBManager.GetAllCategoryTemplates();

            if (NopContext.IsCachable)
            {
                NopCache.Max(key, categoryTemplateCollection);
            }
            return categoryTemplateCollection;
        }

        /// <summary>
        /// Gets a category template
        /// </summary>
        /// <param name="CategoryTemplateID">Category template identifier</param>
        /// <returns>A category template</returns>
        public static CategoryTemplate GetByCategoryTemplateID(int CategoryTemplateID)
        {
            string key = string.Format(CATEGORYTEMPLATES_BY_ID_KEY, CategoryTemplateID);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (CategoryTemplate)obj2;
            }

            CategoryTemplate categoryTemplate = CategoryTemplateDBManager.GetByCategoryTemplateID(CategoryTemplateID);

            if (NopContext.IsCachable)
            {
                NopCache.Max(key, categoryTemplate);
            }
            return categoryTemplate;
        }

        /// <summary>
        /// Inserts a category template
        /// </summary>
        /// <param name="Name">The name</param>
        /// <param name="TemplatePath">The template path</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>A category template</returns>
        public static CategoryTemplate InsertCategoryTemplate(string Name, string TemplatePath,
            int DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn)
        {
            CategoryTemplate categoryTemplate = CategoryTemplateDBManager.InsertCategoryTemplate(Name, TemplatePath,
            DisplayOrder, CreatedOn, UpdatedOn);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_ALL_KEY);
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_BY_ID_KEY);
            }

            return categoryTemplate;
        }

        /// <summary>
        /// Updates the category template
        /// </summary>
        /// <param name="CategoryTemplateID">Category template identifier</param>
        /// <param name="Name">The name</param>
        /// <param name="TemplatePath">The template path</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <param name="CreatedOn">The date and time of instance creation</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>A category template</returns>
        public static CategoryTemplate UpdateCategoryTemplate(int CategoryTemplateID, string Name, string TemplatePath,
            int DisplayOrder, DateTime CreatedOn, DateTime UpdatedOn)
        {
            CategoryTemplate categoryTemplate = CategoryTemplateDBManager.UpdateCategoryTemplate(CategoryTemplateID, Name, TemplatePath,
            DisplayOrder, CreatedOn, UpdatedOn);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_ALL_KEY);
                NopCache.RemoveByPattern(CATEGORYTEMPLATES_BY_ID_KEY);
            }

            return categoryTemplate;
        }
        #endregion
    }
}
